package net.tycmc.cty.ctyms.web.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.tycmc.functions.util.MapGetter;

import net.tycmc.bulb.common.util.DateUtil;
import net.tycmc.cty.ctyms.timejob.common.DateRegUtil;
import net.tycmc.cty.ctyms.timejob.common.ListUtil;
import net.tycmc.cty.ctyms.web.Dao.DataMonitorListDao;

/**
 * 数据监控列表手动执行
 * @author songxiaohu
 *
 */
public class DataMonitorListService {

	private DataMonitorListDao datamld;

	public DataMonitorListDao getDatamld() {
		return datamld;
	}

	public void setDatamld(DataMonitorListDao datamld) {
		this.datamld = datamld;
	}
	
	public Map<String,Object> getdataofHistory(String beginTime,String endTime){
		List<Map<String,Object>>list=datamld.getDataOfHistory(beginTime,endTime);
		List<String>listtime=DateRegUtil.iterateTime(beginTime, endTime);
		Map<String,Object>mapresult=new HashMap<String, Object>();
		Map<String,List<Map<String,Object>>>map=new ListUtil().groupBy("stateTime",list);
		for(int i=listtime.size()-1;i>=0;i--){
			List<Map<String,Object>>listresult=map.get(DateUtil.addDay(beginTime,i));
			if(null==listresult || listresult.size()==0){
				continue;
			}
				for(Map<String,Object>mapparam:listresult){
					String cnt=MapGetter.getString(mapparam,"cnt");
					int type=Integer.parseInt(MapGetter.getString(mapparam,"type"));
					switch (type) {
					case 1:
						mapresult.put("a"+i+"cnt",cnt);
						mapresult.put("a"+i+"time",DateUtil.addDay(beginTime,i));
						break;
					case 2:
						mapresult.put("b"+i+"cnt",cnt);
						mapresult.put("b"+i+"time",DateUtil.addDay(beginTime,i));
						break;
					case 3:
						mapresult.put("c"+i+"cnt",cnt);
						mapresult.put("c"+i+"time",DateUtil.addDay(beginTime,i));
						break;
					case 4:
						mapresult.put("d"+i+"cnt",cnt);
						mapresult.put("d"+i+"time",DateUtil.addDay(beginTime,i));
						break;
					case 5:
						mapresult.put("e"+i+"cnt",cnt);
						mapresult.put("e"+i+"time",DateUtil.addDay(beginTime,i));
						break;
					case 6:
						mapresult.put("f"+i+"cnt",cnt);
						mapresult.put("f"+i+"time",DateUtil.addDay(beginTime,i));
						break;
					default:
						break;
					}
				}
			
		}
		return mapresult;
	}
	public int updateFlagTable(){
		return datamld.updateFlagTable();
	}
}
